package top.codedance.iotp.server.net.initializer;

import cd.io.netty.handler.stream.ChunkedWriteHandler;
import top.codedance.iotp.server.net.handle.HttpChannelHandler;
import top.codedance.iotp.server.net.handle.HttpCounterHandler;
import cd.io.netty.channel.ChannelInitializer;
import cd.io.netty.channel.socket.SocketChannel;
import cd.io.netty.handler.codec.http.HttpObjectAggregator;
import cd.io.netty.handler.codec.http.HttpServerCodec;

public class HttpPipelineInitializer extends ChannelInitializer<SocketChannel> {

    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline()
                .addLast(new HttpServerCodec())
                .addLast("aggregator", new HttpObjectAggregator(1024*1024*1024))
                .addLast("chunkedWriter", new ChunkedWriteHandler())
                .addLast(new HttpChannelHandler(socketChannel))
                .addLast(new HttpCounterHandler());
    }
}
